# -*- coding: utf-8 -*-
"""
-------------------------------------------------
Project Name: luffcity study project
File Name: show_news_page.py
Author: kij
Create Date: 2021/2/12
-------------------------------------------------
"""
from module_two.day15.homework import config


def select_page(page):
	news_list = []
	start_index = (page - 1) * 10
	end_index = page * 10
	with open(config.VIDEO_PATH, mode='rt', encoding='utf-8') as file_video:
		count = 0
		for line in file_video:
			if start_index <= count < end_index:
				news_list.append(''.join(line.strip().split("http")[0].split(",")[1:]))
			if count >= end_index:
				break
			count += 1
	return news_list


def print_news(page_num, news_list):
	print("第{}页".format(page_num).center(50, "*"))
	star_index = (page_num - 1) * 10
	start_contant = 1
	for i in news_list:
		print("第{}条:{}".format(star_index + start_contant, i))
		start_contant += 1

# 根据页数来显示数据
def show_page_by_num():
	while True:
		num = input("输入第几页数字查看，【q或Q退出】:").strip()
		if num.upper() == "Q":
			break
		if num.isdecimal():
			print_news(news_list=select_page(int(num)), page_num=int(num))
		else:
			print_news(1, select_page(1))
